package com.tanhua.common.utils;

import com.tanhua.common.pojo.User;

public class UserThreadLocal {

    private static final ThreadLocal<User> LOCAL = new ThreadLocal<>();
//构造方法私有化,不允许new对象
    private UserThreadLocal() {
    }

    /**
     * 将对象放入到ThreadLocal中
     *
     * @param user
     */
    public static void set(User user) {
        LOCAL.set(user);
    }

    /**
     * 返回当前线程中的User对象
     * @return
     */
    public static User get() {
        return LOCAL.get();
    }

    /**
     * 删除当前线程中的对象,防止内存泄漏
     */
    public static void remove() {
        LOCAL.remove();
    }
}
